local assets =
{
    -- Asset("ANIM", "anim/panda_fisherman_supply_pack.zip"),
    -- Asset( "IMAGE", "images/inventoryimages/panda_fisherman_supply_pack.tex" ),  -- 背包贴图
    -- Asset( "ATLAS", "images/inventoryimages/panda_fisherman_supply_pack.xml" ),
}

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddNetwork()

    inst:AddTag("INLIMBO")
    inst:AddTag("FX")
    inst:AddTag("NOBLOCK")


    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("npc_base_lib")

    inst:DoTaskInTime(0,function()
        if inst.Ready ~= true then
            inst:Remove()
        end
    end)

    inst:ListenForEvent("Set",function(inst,cmd_table)
        -- cmd_table = {
        --     pt = pt, ---Vector3()
        --     name = "log", -- item_name
        --     height = 10,
        --     fn = function    (player,item.prefab)
        -- }

        if cmd_table == nil or cmd_table.pt == nil or cmd_table.name == nil or cmd_table.height == nil then
            return
        end
        local pt = cmd_table.pt
        inst.Transform:SetPosition(pt.x,0,pt.z)

        ------- 创建落点标记
        inst:SpawnChild("npc_fx_pocketwatch_mark"):PushEvent("Set",{ pt = Vector3(0,0.3,0) ,color = Vector3(0,0,180) ,a = 0.4 })
        inst:SpawnChild("npc_fx_pocketwatch_mark"):PushEvent("Set",{ pt = Vector3(0,0.05,0) ,color = Vector3(0,0,0) ,a = 1 ,MultColour_Flag = true})

        local height = cmd_table.height
        local item = SpawnPrefab(cmd_table.name) or SpawnPrefab("log")
        item:AddTag("INLIMBO")
        item:AddTag("FX")
        item:AddTag("NOBLOCK")
        inst.npc_base_lib:Add2Child(item)
        item.__parent = inst
        MakeInventoryPhysics(item)
        item.Physics:SetCollisionGroup(COLLISION.CHARACTERS)
        item.Physics:ClearCollisionMask()
        item.Physics:CollidesWith(COLLISION.WORLD)
        item.Physics:CollidesWith(COLLISION.OBSTACLES)
        item.Physics:CollidesWith(COLLISION.CHARACTERS)
        item.Physics:SetMass(1)
        item.Physics:SetDamping(0.8)
        item.Transform:SetPosition(pt.x,height,pt.z)
        item:DoPeriodicTask(0.2,function()
            local x,y,z = item.Transform:GetWorldPosition()
            if y <= 0.2 then
                SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(x,0,z)
                local ret = item.__parent and item.__parent:Remove()
            end
        end)
        item:DoTaskInTime(5,function()
            local ret = item.__parent and item.__parent:Remove()
            item:Remove()            
        end)
        local function CollidesCallback(item,Collides_target)
            if Collides_target and Collides_target:HasTag("player") then
                if cmd_table.fn and type(cmd_table.fn) == "function" and item and item:IsValid() then
                    cmd_table.fn(Collides_target,item.prefab)
                end
            else
                SpawnPrefab("ground_chunks_breaking").Transform:SetPosition(item.__parent.Transform:GetWorldPosition())
            end

            local ret = item.__parent and item.__parent:Remove()
        end

        item.Physics:SetCollisionCallback(CollidesCallback)


        inst.Ready = true
    end)

    return inst
end

return Prefab("npc_item_catch_game_falling_object", fn,assets)